package cn.songhaiqing.walle.service;

import android.content.Intent;
import android.os.Build;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;

import java.util.Timer;
import java.util.TimerTask;

import cn.songhaiqing.walle.bean.MyApp;

public class MessageNotificationService extends NotificationListenerService {
    private Timer delayTimer;

    /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
    public void onNotificationPosted(StatusBarNotification sbn) {
        String content;
        super.onNotificationPosted(sbn);
        String packageName = sbn.getPackageName();
        if (packageName != null) {
            char c = 65535;
            switch (packageName.hashCode()) {
                case -2099846372:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_SKYPE)) {
                        c = '\b';
                        break;
                    }
                    break;
                case -1938583537:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_VKONTAKTE)) {
                        c = '\f';
                        break;
                    }
                    break;
                case -1651733025:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_VIBER)) {
                        c = 11;
                        break;
                    }
                    break;
                case -1547699361:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_WHATSUP)) {
                        c = 1;
                        break;
                    }
                    break;
                case -1521143749:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_LINE)) {
                        c = 7;
                        break;
                    }
                    break;
                case -973170826:
                    if (packageName.equals("com.tencent.mm")) {
                        c = 6;
                        break;
                    }
                    break;
                case -662003450:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_INSTAGRAM)) {
                        c = '\n';
                        break;
                    }
                    break;
                case -543674259:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_GMAIL)) {
                        c = 2;
                        break;
                    }
                    break;
                case 10619783:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_TWITTER)) {
                        c = 3;
                        break;
                    }
                    break;
                case 361910168:
                    if (packageName.equals("com.tencent.mobileqq")) {
                        c = 5;
                        break;
                    }
                    break;
                case 714499313:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_FACEBOOK)) {
                        c = 4;
                        break;
                    }
                    break;
                case 908140028:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_MESSENGER)) {
                        c = '\t';
                        break;
                    }
                    break;
                case 1153658444:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_LINKEDIN)) {
                        c = 0;
                        break;
                    }
                    break;
                case 1249065348:
                    if (packageName.equals(NotificationAccessbilityService.PACKAGE_KAKAOTALK)) {
                        c = '\r';
                        break;
                    }
                    break;
            }
            switch (c) {
                case 0:
                    if (Build.VERSION.SDK_INT >= 19) {
                        String title = sbn.getNotification().extras.getString(NotificationCompat.EXTRA_TITLE, "");
                        String content2 = sbn.getNotification().extras.getString(NotificationCompat.EXTRA_TEXT, "");
                        String result = "";
                        if (title != null) {
                            result = result + title;
                            if (content2 != null) {
                                result = result + ":" + content2;
                            }
                        }
                        if (result != null) {
                            sendNotificationBroadCast(packageName, result);
                            return;
                        }
                        return;
                    }
                    break;
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case '\b':
                case '\t':
                case '\n':
                case 11:
                case '\f':
                case '\r':
                    break;
                default:
                    return;
            }
            if (sbn.getNotification().tickerText != null && (content = sbn.getNotification().tickerText.toString()) != null) {
                sendNotificationBroadCast(packageName, content);
            }
        }
    }

    private void sendNotificationBroadCast(String packageName, String content) {
        Intent intent = new Intent(NotificationAccessbilityService.NOTIFYCATION_ACTION);
        intent.putExtra(NotificationAccessbilityService.FROM_WHICH_APPLICATION, packageName);
        intent.putExtra(NotificationAccessbilityService.FROM_APPLICATION_CONTENT, content);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }

    public void onNotificationRemoved(StatusBarNotification sbn) {
        //super.onNotificationRemoved(sbn);
    }

    private void startDelayTimer() {
        if (this.delayTimer == null) {
            this.delayTimer = new Timer();
        }
        this.delayTimer.schedule(new TimerTask() {
            /* class com.gzgamut.smart_movement.service.MessageNotificationService.AnonymousClass1 */

            public void run() {
                MyApp.getIntance().setIsSending(false);
                // TimerHelper.cancelTimer(MessageNotificationService.this.delayTimer);
                MessageNotificationService.this.delayTimer = null;
            }
        }, 3000);
    }
}
